package com.betterjr.modules.temhandler.entity;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.mapper.CustDateJsonSerializer;
import com.betterjr.common.mapper.CustTimeJsonSerializer;
import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.common.utils.BetterDateUtils;
import com.betterjr.common.utils.UserUtils;
import com.betterjr.modules.account.entity.CustOperatorInfo;
import com.betterjr.modules.temhandler.data.TemDataConstant;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Access(AccessType.FIELD)
@Entity
@Table(name = "t_tem_data")
public class TemData implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = -8794079062398631620L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     *  状态 0临时表数据新增 1刚插入  2已复核  3已审核   4 生效 9失效
     */
    @Column(name = "c_busin_status", columnDefinition = "VARCHAR")
    @MetaData(value = " 状态 0临时表数据新增1刚插入  2已复核  3已审核  4 生效  9失效", comments = " 状态  0临时表数据新增 1刚插入  2已复核  3已审核   4 生效 9失效")
    private String businStatus;

    /**
     * 业务表类的全路径
     */
    @Column(name = "c_businTable_type", columnDefinition = "VARCHAR")
    @MetaData(value = " 业务表类的全路径", comments = "业务表类的全路径")
    private String businTableType;

    /**
     *  业务表具体数据
     */
    @Column(name = "c_businTable_data", columnDefinition = "VARCHAR")
    @MetaData(value = " 业务表具体数据", comments = "业务表具体数据")
    private String businTableData;

    /**
     * 业务表主键
     */
    @Column(name = "c_businTable_id", columnDefinition = "VARCHAR")
    @MetaData(value = "业务表主键", comments = "业务表主键")
    private String businTableId;

    /**
     *  所属机构
     */
    @Column(name = "c_businTable_operorg", columnDefinition = "VARCHAR")
    @MetaData(value = " 所属机构", comments = "所属机构")
    private String businTableOperorg;

    /**
     * 查询条件1
     */
    @Column(name = "c_queryProperty_one", columnDefinition = "VARCHAR")
    @MetaData(value = " 查询条件1", comments = "查询条件1")
    private String queryOne;

    /**
     * 查询条件2
     */
    @Column(name = "c_queryProperty_two", columnDefinition = "VARCHAR")
    @MetaData(value = " 查询条件2", comments = "查询条件2")
    private String queryTwo;

    /**
     * 查询条件3
     */
    @Column(name = "c_queryProperty_three", columnDefinition = "VARCHAR")
    @MetaData(value = " 查询条件3", comments = "查询条件3")
    private String queryThree;

    /**
     * 查询条件4
     */
    @Column(name = "c_queryProperty_four", columnDefinition = "VARCHAR")
    @MetaData(value = " 查询条件4", comments = "查询条件4")
    private String queryFour;

    /**
     * 查询条件5
     */
    @Column(name = "c_queryProperty_five", columnDefinition = "VARCHAR")
    @MetaData(value = " 查询条件5", comments = "查询条件5")
    private String queryFive;

    /**
     * 版本
     */
    @Column(name = "n_version", columnDefinition = "INTEGER")
    @MetaData(value = "版本", comments = "版本")
    private int version;

    /**
     * 1是最新 0 不是最新
     */
    @Column(name = "c_isLaster", columnDefinition = "VARCHAR")
    @MetaData(value = " 1是最新 0 不是最新", comments = "1是最新 0 不是最新")
    private String laster;

    /**
     * 上一手id
     */
    @Column(name = "n_prefixId", columnDefinition = "INTEGER")
    @MetaData(value = "上一手id", comments = "上一手id")
    private Long prefixId;

    /**
     * 企业编号
     */
    @Column(name = "L_CUSTNO", columnDefinition = "INTEGER")
    @MetaData(value = "企业编号", comments = "企业编号")
    private Long custNo;

    /**
     * 企业名称
     */
    @Column(name = "C_CUSTNAME", columnDefinition = "VARCHAR")
    @MetaData(value = " 企业名称", comments = "企业名称")
    private String custName;

    /**
     *备注
     */
    @Column(name = "c_description", columnDefinition = "VARCHAR")
    @MetaData(value = " 备注", comments = "备注")
    private String description;

    /**
     * 注册人
     */
    @Column(name = "L_reg_operid", columnDefinition = "INTEGER")
    @MetaData(value = "注册人", comments = "注册人")
    private Long regOperid;

    /**
     *注册名称
     */
    @Column(name = "c_reg_opername", columnDefinition = "VARCHAR")
    @MetaData(value = " 注册名称", comments = "注册名称")
    private String regOpername;

    /**
     *注册时间
     */
    @Column(name = "t_reg_time", columnDefinition = "VARCHAR")
    @MetaData(value = " 注册时间", comments = "注册时间")
    @JsonSerialize(using = CustTimeJsonSerializer.class)
    private String regTime;

    /**
     *注册日期
     */
    @Column(name = "d_reg_date", columnDefinition = "VARCHAR")
    @MetaData(value = " 注册日期", comments = "注册日期")
    @JsonSerialize(using = CustDateJsonSerializer.class)
    private String regDate;

    /**
     * 审核人
     */
    @Column(name = "l_audit_operid", columnDefinition = "INTEGER")
    @MetaData(value = "审核人", comments = "审核人")
    private Long auditOperid;

    /**
     *审核名称
     */
    @Column(name = "c_audit_opername", columnDefinition = "VARCHAR")
    @MetaData(value = " 审核名称", comments = "审核名称")
    private String auditOpername;

    /**
     *审核时间
     */
    @Column(name = "t_audit_time", columnDefinition = "VARCHAR")
    @MetaData(value = " 审核时间", comments = "审核时间")
    @JsonSerialize(using = CustTimeJsonSerializer.class)
    private String auditTime;

    /**
     *审核时间
     */
    @Column(name = "d_audit_date", columnDefinition = "VARCHAR")
    @MetaData(value = " 审核时间", comments = "审核时间")
    @JsonSerialize(using = CustDateJsonSerializer.class)
    private String auditDate;

    /**
     * 处理结果  1处理成功  9处理失败
     */
    @Column(name = "c_handler_result", columnDefinition = "VARCHAR")
    @MetaData(value = " 处理结果  1处理成功  9处理失败", comments = "处理结果  1处理成功  9处理失败")
    private String handlerResult;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public String getBusinTableType() {
        return businTableType;
    }

    public void setBusinTableType(String businTableType) {
        this.businTableType = businTableType;
    }

    public Long getCustNo() {
        return custNo;
    }

    public void setCustNo(Long custNo) {
        this.custNo = custNo;
    }

    public String getCustName() {
        return custName;
    }

    public void setCustName(String custName) {
        this.custName = custName;
    }

    public String getBusinTableData() {
        return businTableData;
    }

    public void setBusinTableData(String businTableData) {
        this.businTableData = businTableData;
    }

    public String getBusinTableId() {
        return businTableId;
    }

    public void setBusinTableId(String businTableId) {
        this.businTableId = businTableId;
    }

    public String getBusinTableOperorg() {
        return businTableOperorg;
    }

    public void setBusinTableOperorg(String businTableOperorg) {
        this.businTableOperorg = businTableOperorg;
    }

    public String getQueryOne() {
        return queryOne;
    }

    public void setQueryOne(String queryOne) {
        this.queryOne = queryOne;
    }

    public String getQueryTwo() {
        return queryTwo;
    }

    public void setQueryTwo(String queryTwo) {
        this.queryTwo = queryTwo;
    }

    public String getQueryThree() {
        return queryThree;
    }

    public void setQueryThree(String queryThree) {
        this.queryThree = queryThree;
    }

    public String getQueryFour() {
        return queryFour;
    }

    public void setQueryFour(String queryFour) {
        this.queryFour = queryFour;
    }

    public String getQueryFive() {
        return queryFive;
    }

    public void setQueryFive(String queryFive) {
        this.queryFive = queryFive;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public String getLaster() {
        return laster;
    }

    public void setLaster(String laster) {
        this.laster = laster;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getRegOperid() {
        return regOperid;
    }

    public void setRegOperid(Long regOperid) {
        this.regOperid = regOperid;
    }

    public String getRegOpername() {
        return regOpername;
    }

    public void setRegOpername(String regOpername) {
        this.regOpername = regOpername;
    }

    public String getRegTime() {
        return regTime;
    }

    public void setRegTime(String regTime) {
        this.regTime = regTime;
    }

    public String getRegDate() {
        return regDate;
    }

    public void setRegDate(String regDate) {
        this.regDate = regDate;
    }

    public Long getPrefixId() {
        return prefixId;
    }

    public void setPrefixId(Long prefixId) {
        this.prefixId = prefixId;
    }

    public Long getAuditOperid() {
        return auditOperid;
    }

    public void setAuditOperid(Long auditOperid) {
        this.auditOperid = auditOperid;
    }

    public String getAuditOpername() {
        return auditOpername;
    }

    public void setAuditOpername(String auditOpername) {
        this.auditOpername = auditOpername;
    }

    public String getAuditTime() {
        return auditTime;
    }

    public void setAuditTime(String auditTime) {
        this.auditTime = auditTime;
    }

    public String getAuditDate() {
        return auditDate;
    }

    public void setAuditDate(String auditDate) {
        this.auditDate = auditDate;
    }

    public String getHandlerResult() {
        return handlerResult;
    }

    public void setHandlerResult(String handlerResult) {
        this.handlerResult = handlerResult;
    }

    @Override
    public String toString() {
        return "TemData [id=" + id + ", businStatus=" + businStatus + ", businTableType=" + businTableType
                + ", businTableData=" + businTableData + ", businTableId=" + businTableId + ", businTableOperorg="
                + businTableOperorg + ", queryOne=" + queryOne + ", queryTwo=" + queryTwo + ", queryThree=" + queryThree
                + ", queryFour=" + queryFour + ", queryFive=" + queryFive + ", version=" + version + ", laster="
                + laster + ", prefixId=" + prefixId + ", custNo=" + custNo + ", custName=" + custName + ", description="
                + description + ", regOperid=" + regOperid + ", regOpername=" + regOpername + ", regTime=" + regTime
                + ", regDate=" + regDate + ", auditOperid=" + auditOperid + ", auditOpername=" + auditOpername
                + ", auditTime=" + auditTime + ", auditDate=" + auditDate + ", handlerResult=" + handlerResult + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((auditDate == null) ? 0 : auditDate.hashCode());
        result = prime * result + ((auditOperid == null) ? 0 : auditOperid.hashCode());
        result = prime * result + ((auditOpername == null) ? 0 : auditOpername.hashCode());
        result = prime * result + ((auditTime == null) ? 0 : auditTime.hashCode());
        result = prime * result + ((businStatus == null) ? 0 : businStatus.hashCode());
        result = prime * result + ((businTableData == null) ? 0 : businTableData.hashCode());
        result = prime * result + ((businTableId == null) ? 0 : businTableId.hashCode());
        result = prime * result + ((businTableOperorg == null) ? 0 : businTableOperorg.hashCode());
        result = prime * result + ((businTableType == null) ? 0 : businTableType.hashCode());
        result = prime * result + ((description == null) ? 0 : description.hashCode());
        result = prime * result + ((handlerResult == null) ? 0 : handlerResult.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((laster == null) ? 0 : laster.hashCode());
        result = prime * result + ((prefixId == null) ? 0 : prefixId.hashCode());
        result = prime * result + ((queryFive == null) ? 0 : queryFive.hashCode());
        result = prime * result + ((queryFour == null) ? 0 : queryFour.hashCode());
        result = prime * result + ((queryOne == null) ? 0 : queryOne.hashCode());
        result = prime * result + ((queryThree == null) ? 0 : queryThree.hashCode());
        result = prime * result + ((queryTwo == null) ? 0 : queryTwo.hashCode());
        result = prime * result + ((regDate == null) ? 0 : regDate.hashCode());
        result = prime * result + ((regOperid == null) ? 0 : regOperid.hashCode());
        result = prime * result + ((regOpername == null) ? 0 : regOpername.hashCode());
        result = prime * result + ((regTime == null) ? 0 : regTime.hashCode());
        result = prime * result + version;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof TemData)) {
            return false;
        }
        TemData other = (TemData) obj;
        if (auditDate == null) {
            if (other.auditDate != null) {
                return false;
            }
        } else if (!auditDate.equals(other.auditDate)) {
            return false;
        }
        if (auditOperid == null) {
            if (other.auditOperid != null) {
                return false;
            }
        } else if (!auditOperid.equals(other.auditOperid)) {
            return false;
        }
        if (auditOpername == null) {
            if (other.auditOpername != null) {
                return false;
            }
        } else if (!auditOpername.equals(other.auditOpername)) {
            return false;
        }
        if (auditTime == null) {
            if (other.auditTime != null) {
                return false;
            }
        } else if (!auditTime.equals(other.auditTime)) {
            return false;
        }
        if (businStatus == null) {
            if (other.businStatus != null) {
                return false;
            }
        } else if (!businStatus.equals(other.businStatus)) {
            return false;
        }
        if (businTableData == null) {
            if (other.businTableData != null) {
                return false;
            }
        } else if (!businTableData.equals(other.businTableData)) {
            return false;
        }
        if (businTableId == null) {
            if (other.businTableId != null) {
                return false;
            }
        } else if (!businTableId.equals(other.businTableId)) {
            return false;
        }
        if (businTableOperorg == null) {
            if (other.businTableOperorg != null) {
                return false;
            }
        } else if (!businTableOperorg.equals(other.businTableOperorg)) {
            return false;
        }
        if (businTableType == null) {
            if (other.businTableType != null) {
                return false;
            }
        } else if (!businTableType.equals(other.businTableType)) {
            return false;
        }
        if (description == null) {
            if (other.description != null) {
                return false;
            }
        } else if (!description.equals(other.description)) {
            return false;
        }
        if (handlerResult == null) {
            if (other.handlerResult != null) {
                return false;
            }
        } else if (!handlerResult.equals(other.handlerResult)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (laster == null) {
            if (other.laster != null) {
                return false;
            }
        } else if (!laster.equals(other.laster)) {
            return false;
        }
        if (prefixId == null) {
            if (other.prefixId != null) {
                return false;
            }
        } else if (!prefixId.equals(other.prefixId)) {
            return false;
        }
        if (queryFive == null) {
            if (other.queryFive != null) {
                return false;
            }
        } else if (!queryFive.equals(other.queryFive)) {
            return false;
        }
        if (queryFour == null) {
            if (other.queryFour != null) {
                return false;
            }
        } else if (!queryFour.equals(other.queryFour)) {
            return false;
        }
        if (queryOne == null) {
            if (other.queryOne != null) {
                return false;
            }
        } else if (!queryOne.equals(other.queryOne)) {
            return false;
        }
        if (queryThree == null) {
            if (other.queryThree != null) {
                return false;
            }
        } else if (!queryThree.equals(other.queryThree)) {
            return false;
        }
        if (queryTwo == null) {
            if (other.queryTwo != null) {
                return false;
            }
        } else if (!queryTwo.equals(other.queryTwo)) {
            return false;
        }
        if (regDate == null) {
            if (other.regDate != null) {
                return false;
            }
        } else if (!regDate.equals(other.regDate)) {
            return false;
        }
        if (regOperid == null) {
            if (other.regOperid != null) {
                return false;
            }
        } else if (!regOperid.equals(other.regOperid)) {
            return false;
        }
        if (regOpername == null) {
            if (other.regOpername != null) {
                return false;
            }
        } else if (!regOpername.equals(other.regOpername)) {
            return false;
        }
        if (regTime == null) {
            if (other.regTime != null) {
                return false;
            }
        } else if (!regTime.equals(other.regTime)) {
            return false;
        }
        if (version != other.version) {
            return false;
        }
        return true;
    }

    public void saveAddInitValue(int anVersion) {

        this.id = SerialGenerator.getLongValue("TemData.id");
        if (StringUtils.isBlank(this.businStatus)) {

            this.businStatus = TemDataConstant.TEMDATA_BUSINSTATUS_INSERTED;
        }
        this.laster = TemDataConstant.TEMDATA_LASTER_YES;
        this.version = anVersion;
        this.prefixId = 0L;
        CustOperatorInfo operatorInfo = UserUtils.getOperatorInfo();
        this.setRegOperid(operatorInfo.getId());
        this.setRegOpername(operatorInfo.getName());
        this.setRegTime(BetterDateUtils.getNumTime());
        this.setRegDate(BetterDateUtils.getNumDate());
    }

    public void saveAuditValue(CustOperatorInfo operatorInfo, String anDescription, String handlerResult) {

        this.setAuditDate(BetterDateUtils.getNumDate());
        this.setAuditOperid(operatorInfo.getId());
        this.setAuditOpername(operatorInfo.getName());
        this.setAuditTime(BetterDateUtils.getNumTime());
        this.setDescription(anDescription);
        this.setHandlerResult(handlerResult);
    }

}
